package zhanglinwei.cryptotools.core.wrapper;

import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.PropertySource;
import zhanglinwei.cryptotools.core.resolver.CryptoablePropertyResolver;
import zhanglinwei.cryptotools.core.source.CacheCryptoablePropertySource;
import zhanglinwei.cryptotools.core.source.CryptoablePropertySource;

import java.util.Map;

public class CryptoableMapPropertySourceWrapper extends MapPropertySource implements CryptoablePropertySource<Map<String, Object>> {

    private final CacheCryptoablePropertySource<Map<String, Object>> cacheCryptoableDelegate;

    public CryptoableMapPropertySourceWrapper(MapPropertySource delegate, CryptoablePropertyResolver resolver) {
        super(delegate.getName(), delegate.getSource());
        cacheCryptoableDelegate = new CacheCryptoablePropertySource<>(delegate, resolver);
    }

    @Override
    public PropertySource<Map<String, Object>> getDelegate() {
        return cacheCryptoableDelegate;
    }

    @Override
    public Object getProperty(String name) {
        return cacheCryptoableDelegate.getProperty(name);
    }

    @Override
    public void refresh() {

    }
}
